package com.sunsharing.flow.event;


import com.sunsharing.common.utils.StringUtils;

/**
 * Created with IntelliJ IDEA.
 * User: criss
 * Date: 13-5-4
 * Time: 下午7:41
 * To change this template use File | Settings | File Templates.
 */
public abstract class ApplicationEvent {

    /**主键**/
    private long id;

    /**源对象**/
    private  Object source;

    /**事件发生的时间**/
    private final String timestamp;


    /**描述**/
    private String desc;


    public ApplicationEvent(){
        this.timestamp = StringUtils.getCurrentTime();

    }


    /**
     * 功能描述:
     *     创建一个新的应用事件
     * @param source Object
     */
    public ApplicationEvent(Object source) {
        if (source == null)
            throw new IllegalArgumentException("源对象不能为空!");
        this.source = source;
        this.timestamp = StringUtils.getCurrentTime();

    }


    /**
     * 功能描述:
     *    获得源对象
     * @return Object
     */
    public Object getSource() {
        return this.source;
    }


    /**
     * 功能描述:
     *     返回时间
     * @return long
     */
    public final String getTimestamp() {
        return this.timestamp;
    }




    public long getId() {
        return id;
    }

    public String getDesc() {
        return desc;
    }




    /**
     * 功能描述:
     *     覆盖equals方法
     * @param obj Object
     * @return boolean
     */
    public boolean equals(Object obj) {

        if(obj == null) {
            return false;
        }
        if(obj.getClass().getName().equals(this.getClass().getName())) {
            return true;
        }
        return false;

    }

    public void setId(long id) {
        this.id = id;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }


}
